package com.nchu.chatserver.controller;

import com.nchu.chatserver.dao.ContactUserDTO;
import com.nchu.chatserver.dao.LoginDTO;
import com.nchu.chatserver.dao.UserDTO;
import com.nchu.chatserver.entity.User;
import com.nchu.chatserver.service.ContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 王小航
 * @Date: 2025/05/07/22:15
 * @Description:
 */
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api/contacts")
public class ContactController {
    @Autowired
    private ContactService contactService;
    @GetMapping("/test")
    public ResponseEntity<String> test() {
        return ResponseEntity.ok("123");
    }


    @GetMapping("/getContacts")
    public ResponseEntity<List<UserDTO>> getContacts(@RequestParam Integer userId) {
        return ResponseEntity.ok(contactService.getContacts(userId));
    }

    @GetMapping("/getContactsAndUnread")
    public ResponseEntity<List<ContactUserDTO>> getContactsAndUnread(@RequestParam Integer userId) {
        return ResponseEntity.ok(contactService.getContactsAndUnread(userId));
    }
    @PostMapping("/addContact")
    public ResponseEntity<UserDTO> addContact(@RequestParam Integer userId, @RequestParam String username) {

        return ResponseEntity.ok(contactService.addContact(userId, username));
    }


    @DeleteMapping("/deleteContact")
    public ResponseEntity<Void> deleteContact(@RequestParam Integer userId, @RequestParam Integer contactId) {
        contactService.removeContact(userId, contactId);
        return ResponseEntity.ok().build();
    }
}